package ThreadPool.jike.demo04;

/**
 * @param
 * @author oyz
 * @version 1.1.0
 * @description: 粗粒度锁
 * @date 2022-9-15 15:35
 */
public class Account {

    // 金额锁
    private final Object baLock = new Object();

    // 密码锁
    private final Object pwLock = new Object();

    private Integer balance;

    private String password;

    // 取款
    public void withDrow(Integer money){
        synchronized (baLock){
            if(balance >= money){
                this.balance -= money;
            }
        }
    }
    // 查看余额
    Integer getBalance() {
        synchronized(baLock) {
            return balance;
        }
    }
    // 更改密码
    void updatePassword(String pw){
        synchronized(pwLock) {
            this.password = pw;
        }
    }

    // 转账 把锁粒度调大
    void transfer(Integer balance,Integer money){
        synchronized (Account.class){
            // 实现转账业务

        }
    }






}
